<?php
/**
 * Base Model class for Oauth applications
 */
class Social_Oauth_BaseModel {
	/**
	 * @var Zend_Oauth_Token_Access 
	 */
	protected $token;
	/**
	 * @var Array
	 */
	protected $oauthOptions;
	/**
	 * Constructor 
	 * @param Zend_Oauth_Token_Access
	 * @param Array
	 */
	public function __construct( Zend_Oauth_Token_Access $token, Array $options )
	{
		$this->token = $token;
		$this->oauthOptions = $options;
	}
	/**
	 * Make a call using Oauth client
	 * @param String
	 */
	protected function request( $url, $method=Zend_Http_Client::GET )
	{
		$http = $this->token->getHttpClient($this->oauthOptions);
		$http->setUri($url);
		$http->setMethod($method);
		switch($method)
		{
			case Zend_Http_Client::PUT:
				//$this->client->setParameterPost('access_token',$this->access_token);
				//$this->client->setEncType(self::ENC_FORMDATA);
				break;
			case Zend_Http_Client::POST:
				//$this->client->setParameterPost('access_token', $this->access_token);
				break;
			case Zend_Http_Client::GET:
			case Zend_Http_Client::DELETE:
			default:
				//$this->client->setParameterGet('access_token',$this->access_token);
				break;
		}
		try
		{
			$response = $http->request();
			$data = $response->getBody();
		}
		catch (Zend_Http_Client_Exception $e)
		{
			// Return Exception as JSON
			$data = new stdClass;
			$data->code = $e->getCode();
			$data->error = $e->getMessage();
		}
		return $data;
	}
}